package com.shycloud.mido.basic.controller;


import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.shycloud.mido.basic.api.entity.*;
import com.shycloud.mido.basic.api.enums.MessageCodeEnum;
import com.shycloud.mido.basic.service.*;
import com.shycloud.mido.common.core.util.R;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *  获取信息
 * @author liuW
 */
@RestController
@AllArgsConstructor
@RequestMapping("/v1/mobile")
@Api(value = "mobile", description = "基础数据手机接口")
public class MobileController {

	private final BasCitiesService basCitiesService;
	private final BasAreasService basAreasService;
	private final BasDictionaryService basDictionaryService;
	private final BasGradeOrganService basGradeOrganService;
	private final BasProvincesService basProvincesService;
	private final BasSubjectService basSubjectService;

	/**
	 * 根据类型查询字典表
	 *
	 * @param type    类型
	 * @return  R
	 */
	@GetMapping("/getDictionary")
	public R getDictionary(@RequestParam(value="type") String type) {
		// 查询字典表
		List<BasDictionary> dictionaryList = basDictionaryService.list(Wrappers
				.<BasDictionary>query().lambda()
				.eq(BasDictionary::getType, type));
		Map<String,Object> map = new HashMap<String,Object>();
		if (CollUtil.isEmpty(dictionaryList)) {
			return new R<>(Boolean.FALSE, MessageCodeEnum.MEMBER_ERROR_201.getMessage()).setCode(MessageCodeEnum.MEMBER_ERROR_201.getCode());
		}
		map.put("list",dictionaryList);
		return new R<>(map, MessageCodeEnum.SUCCESS.getMessage());
	}

	/**
	 * 查找考级单位
	 *
	 * @return 考级单位
	 */
	@GetMapping("/getGradeOrgan")
	public R getGradeOrgan() {
		// 查询字典表
		List<BasGradeOrgan> gradeOrganList = basGradeOrganService.list();
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("list",gradeOrganList);
		return new R<>(map, MessageCodeEnum.SUCCESS.getMessage());
	}

	/**
	 * 查询省份名称列表
	 *
	 * @return 省份列表
	 */
	@GetMapping("/getProvinces")
	public R getProvinces() {
		// 查询字典表
		List<BasProvinces> provincesList = basProvincesService.list();
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("list", provincesList);
		return new R<>(map, MessageCodeEnum.SUCCESS.getMessage());
	}

	/**
	 * 根据省份名查询城市列表
	 *
	 * @return 城市列表
	 */
	@GetMapping("/getSubject")
	public R getSubject() {
		// 查询字典表
		List<BasSubject> subjectList = basSubjectService.list();
		Map<String,Object> map = new HashMap<String,Object>();
		if (CollUtil.isEmpty(subjectList)) {
			return new R<>(Boolean.FALSE, MessageCodeEnum.MEMBER_ERROR_202.getMessage()).setCode(MessageCodeEnum.MEMBER_ERROR_202.getCode());
		}
		map.put("list", subjectList);
		return new R<>(map, MessageCodeEnum.SUCCESS.getMessage());
	}

	/**
	 * 根据省份名查询城市列表
	 *
	 * @param provincesId   省份id
	 * @return 城市列表
	 */
	@GetMapping("/getCities")
	public R getCities(@RequestParam(value="provincesId") String provincesId) {
		// 查询字典表
		List<BasCities> citiesList = basCitiesService.list(Wrappers
				.<BasCities>query().lambda()
				.eq(BasCities::getProvinceid, provincesId));
		Map<String,Object> map = new HashMap<String,Object>();
		if (CollUtil.isEmpty(citiesList)) {
			return new R<>(Boolean.FALSE, MessageCodeEnum.MEMBER_ERROR_202.getMessage()).setCode(MessageCodeEnum.MEMBER_ERROR_202.getCode());
		}
		map.put("list", citiesList);
		return new R<>(map, MessageCodeEnum.SUCCESS.getMessage());
	}

	/**
	 * 根据城市名查询地区列表
	 *
	 * @param cityId   城市id
	 * @return 地区列表
	 */
	@GetMapping("/getAreas")
	public R getAreas(@RequestParam(value="cityId") String cityId) {
		// 查询字典表
		List<BasAreas> areasList = basAreasService.list(Wrappers
				.<BasAreas>query().lambda()
				.eq(BasAreas::getCityid, cityId));
		Map<String,Object> map = new HashMap<String,Object>();
		if (CollUtil.isEmpty(areasList)) {
			return new R<>(Boolean.FALSE, MessageCodeEnum.MEMBER_ERROR_203.getMessage()).setCode(MessageCodeEnum.MEMBER_ERROR_203.getCode());
		}
		map.put("list", areasList);
		return new R<>(map, MessageCodeEnum.SUCCESS.getMessage());
	}

	/**
	 *  课程详情-联系情况字典表查询
	 * @return
	 */
	@PostMapping("/practiceDic")
	public R practiceDic(){
		return basDictionaryService.practiceDic();
	}

	/**
	 * 学生评价陪练教师标签字典表查询
	 * @return
	 */
	@PostMapping("/tagDic")
	public R tagDic(){ return basDictionaryService.tagDic();}

	/**
	 * 上课偏好标签字典查询
	 * @return
	 */
	@PostMapping("preferenceDic")
	public R preferenceDic(){ return basDictionaryService.preferenceDic();}

}
